package img;

import com.google.zxing.BinaryBitmap;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;
import com.google.zxing.qrcode.QRCodeWriter;

import javax.imageio.ImageIO;
import java.io.File;

/**
 * @author wzby
 * @Date: 2022/8/4 14:01
 */
public class ImgQr2 {
    public static void main(String[] args) {
        //解读二维码
        try {
            var img = ImageIO.read(new File("ch09/src/pho/qr1.png"));
         var src = new BufferedImageLuminanceSource(img);
         var bi = new HybridBinarizer(src);
         var bb = new BinaryBitmap(bi);
         var r = new QRCodeReader().decode(bb);
         //二维码阅读器
         System.out.println(r.getText());
        }catch (Exception e){
            System.out.println("没有二维码");
        }
    }
}
